﻿using System;
using Trackr.Core.Aspects;

namespace Trackr.Core.Entities
{
    [NotifyPropertyChanged]
    public class TimeItem
    {
        public TimeItem()
        {
        }

        public TimeItem(string task)
        {
            Task = task;
            StartDate = DateTime.Now;
            Id = -1;
        }

        public int Id { get; set; }
        public string Task { get; set; }
        public double RunningSeconds { get; set; }
        public DateTime StartDate { get; set; }

        public string TaskDuration
        {
            get { return GetDuration().ToString("h':'m'h'"); }
        }

        public TimeSpan GetDuration()
        {
            if (RunningSeconds == 0)
                return DateTime.Now.Subtract(StartDate);
            return TimeSpan.FromSeconds(RunningSeconds);
        }

        public void AddDuration(TimeSpan time)
        {
            AddDuration(time.TotalSeconds);
        }

        public void AddDuration(double seconds)
        {
            RunningSeconds = RunningSeconds + seconds;
        }

        public IProject GetProject()
        {
            throw new NotImplementedException();
        }
    }
}